<?php
/*
	获取活动详情
	电商客商品列表页和商品详情页会调用本方法以获得商品详情
*/
defined('BY_JYA') or exit('error');
list($type,$posterid,$goodsid,$openid,$qr,$posterdata,$pluginname,$id,$isup)=$arguments;
		$openid=$openid?:$_SESSION['openid'];
		$m=pdo_get('core_fans',array('openid'=>$openid,'uniacid'=>$_SESSION['uniacid']));
		$m['mid']=$_SESSION['uid']?:$m['mid'];
		$m['nickname']=$posterdata['nickname']?:$m['nickname'];
		$m['avatar']=$posterdata['avatar']?:$m['avatar'];
		$member['mid']=$m['mid'];
		$member['nickname']=$m['nickname'];
		$member['avatar']=$m['avatar']?:'../core/resource/images/gw-user.png';
		$query='&id='.$id;
		if(!$type && !$posterid && !$posterdata){
			return false;
		}
		if($type==3 && (!$posterid || $posterid=='goods')){
			$item=$this->plugin_setting('goodsposter')?:array();
			$data=$this->goodsdatademo;
			$item['data']['data']=$item['data']['data']?:$data;
			$item['type']=3;
			$item['id']='goods';
			$item['title']='商品';
		}elseif($posterdata){
			$item['data']=$posterdata;
		}elseif($type=='api'){
			$item=plugin($pluginname)->plugin_setting('poster')?:array();
			$data=$this->apidatademo;
			$item['data']['data']=$item['data']['data']?:$data;
			$item['type']='api';
			$item['id']='api';
			$item['title']=$item['title'];
		}else{
			if($posterid){
				$params=array('id'=>$posterid,'uniacid'=>$_SESSION['uniacid']);
			}elseif($type){
				$params=array('type'=>$type,'isdefault'=>1,'uniacid'=>$_SESSION['uniacid']);
			}
			if($posterid){
				$item=pdo_get('jy_poster_poster',$params);
			}else{
				$item=pdo_get('jy_poster_poster',$params);
				if(!$item['id']){
					$item=pdo_get('jy_poster_poster',array('type'=>$type,'uniacid'=>$_SESSION['uniacid']));	
				}
			}
			if(!$item['id']){
				return false;
			}
			$item['data']=json_decode($item['data'],true);
		}		
		$poster['id']=$item['id'];
		$poster['data']=$item['data']['data'];
		$poster['bg']=$item['data']['image'];
		$poster['height']=$item['data']['height']?:1008;
		if($item['type']==1){
			if($_SESSION['fromh5wxapp']){
				$url='jy_poster/code//id='.$poster['id'].'&f='.$m['mid'];
				$url='/pages/index/index?url='.urlencode($url);
			}elseif($_SESSION['container']=='wxapp'){
				$url='/jy_weishop/index/index?poster='.$poster['id'].'&fromuser='.$m['mid'];
			}else{
				$url=custom_url('jy_poster/code//id='.$poster['id'].'&f='.$m['mid'],true);
			}
		}elseif($item['type']==2){
			if($_SESSION['fromh5wxapp']){
				$url='jy_poster/code//id='.$poster['id'].'&f='.$m['mid'].'&mid='.$m['mid'];
				$url='/pages/index/index?url='.urlencode($url);
			}elseif($_SESSION['container']=='wxapp'){
				$url='/jy_weishop/merch/index?poster='.$poster['id'].'&fromuser='.$m['mid'].'&uid='.$m['mid'];
			}else{
				$url=custom_url('jy_poster/code//id='.$poster['id'].'&f='.$m['mid'].'&mid='.$m['mid'],true);
			}
		}elseif($item['type']==3){
			$pluginname=$pluginname?:'jy_weishop';
			if($_SESSION['fromh5wxapp']){
				$url='jy_poster/code//id='.$poster['id'].'&f='.$m['mid'].'&g='.$goodsid;
				$url='/pages/index/index?url='.urlencode($url);
			}elseif($_SESSION['container']=='wxapp'){
				$url='/'.$pluginname.'/index/goods/detail/index?poster='.$poster['id'].'&fromuser='.$m['mid'].'&id='.$goodsid;
			}else{
				$url=custom_url('jy_poster/code//id='.$poster['id'].'&f='.$m['mid'].'&goodsid='.$goodsid.'&pluginname='.$pluginname,true);
			}
		}elseif($item['type']==4){
			if($_SESSION['fromh5wxapp']){
				$url='jy_poster/code//id='.$poster['id'].'&f='.$m['mid'].'&mid='.$m['mid'];
				$url='/pages/index/index?url='.urlencode($url);
			}elseif($_SESSION['container']=='wxapp'){
				//小程序先不计算海报佣金
				$url='/jy_commission/myshop/index?poster='.$poster['id'].'&fromuser='.$m['mid'].'&mid='.$m['mid'];
			}else{
				$url=custom_url('jy_poster/code//id='.$poster['id'].'&f='.$m['mid'].'&mid='.$m['mid'],true);
			}
		}elseif($item['type']==5){
			if($_SESSION['fromh5wxapp']){
				$url='jy_poster/code//id='.$poster['id'].'&fromuser='.$m['mid'];
				$url='/pages/index/index?url='.urlencode($url);
			}elseif($_SESSION['container']=='wxapp'){
				$url='/jy_poster/code/index?id='.$poster['id'].'&fromuser='.$m['mid'];
			}else{
				$url=custom_url('jy_poster/code//id='.$poster['id'].'&f='.$m['mid'],true);
			}
		}elseif($item['type']==6){
			//关注海报
		}elseif($item['type']=='api'){
			//插件海报
			$goodsid=$pluginname;
			if($_SESSION['fromh5wxapp'] || $_SESSION['container']=='wxapp'){
				$url='jy_poster/apicode//j='.$pluginname.'&f='.$m['mid'].$query;
				$url='/pages/index/index?url='.urlencode($url);
			}else{
				$url=custom_url('jy_poster/apicode//j='.$pluginname.'&f='.$m['mid'].$query,true);
			}
		}
		if(!$qr){
			$goodsid=$goodsid?:$posterid;
			$image='oss/'.$_SESSION['uniacid'].'/images/jy_poster/wxappid'.$m['mid'].'g'.$goodsid.'.jpg';
			$isadd=cfc('files')->source_check($image);
			if($_SESSION['wxapp_id']){
				if(!$isadd){
					$qr=$this->model('model')->get_wxappewm($url,$goodsid);
				}else{
					$qr=$image;
				}
			}else{
				if($item['type']==6){
					$qr=$this->model('model')->get_subscribeqr($item);
				}else{
					$qr=cfc('tools')->createqrcode($url,150,true);
				}
			}
		}
		//file_put_contents(ROOT_D.'/1.txt',$qr.'~~'.$url.'~~'.$item['type']);
		$img=$this->model()->createPoster($poster,$qr,$member,$goodsid,$pluginname,$isup);
		$return=$item;
		$return['member']=$member;
		$return['posterid']=$item['id'];
		$return['poster']=tomedia($img);
		pdo_update('jy_poster_poster',array('times +='=>1),array('id'=>$item['id'],'uniacid'=>$_SESSION['uniacid']));
return $return;